home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DDJMAG / DDJ8801.ZIP / HOLUB.ZIP / HOLUB.EXP
Text File  |  1987-10-29  |  6KB  |  168 lines

  1. ________________________________________________________________
  2.                                      Fig.  1: 
  3.  
  4.  
  5.                        +-----------------------------+
  6.                        |            tasks            |
  7.                        |  +-----------------------+  |
  8.                        |  |         kernel        |  |
  9.                        |  |  +-----------------+  |  |
  10.                        |  |  |    I/O system   |  |  |
  11.                        |  |  |  +-----------+  |  |  |
  12.                        |  |  |  | interrupt |  |  |  |
  13.                        |  |  |  |  system   |  |  |  |
  14.                        |  |  |  +-----------+  |  |  |
  15.                        |  |  +-----------------+  |  |
  16.                        |  +-----------------------+  |
  17.                        +-----------------------------+
  18.  
  19.                        +-----------------------+-------+
  20.                        |        kernel         |       |
  21.                        +-----------+-----------+       |
  22.                        |           |  DOS      | tasks |
  23.                        |           +--------+  |       |
  24.                        | interrupt |  I/O   |  |       |
  25.                        |  system   | system |  |       |
  26.                        |           |        |  |       |
  27.                        +-----------+--------+--+-------+
  28.  
  29.        
  30. ________________________________________________________________
  31.  
  32. _______________________________________________________________
  33.                                    Example  1: 
  34.  
  35.  
  36.          typedef struct tcb
  37.          {
  38.              void          **sp;         /* Task-swap stuff */
  39.              unsigned      ss;
  40.  
  41.              unsigned      priority;
  42.              unsigned long timestamp;
  43.  
  44.              unsigned      wait;         /* Message-management
  45. stuff */
  46.              struct tcb    *next;
  47.              void          *msg;
  48.  
  49.              int           status;       /* debugging stuff */
  50.              char          *tag;
  51.              void          **initial_sp
  52.  
  53.              void          *stack[1];    /* Base of system stack
  54. */
  55.          }
  56.          TCB;
  57.  
  58.        
  59. ________________________________________________________________
  60.  
  61. ________________________________________________________________
  62.                                      Fig.  2: 
  63.  
  64.                                +---------------+
  65.                                | TCB structure |
  66.                                +---------------+
  67.                                |               |
  68.                                |               |
  69.                                |    task's     |
  70.                                |    stack      |
  71.                                |               |
  72.                                |               |
  73.                                |               |
  74.                                |               |
  75.                                +---------------+
  76.  
  77.        
  78. ________________________________________________________________
  79.  
  80. ________________________________________________________________
  81.                                    Example  2: 
  82.  
  83.  
  84.               typedef struct t_queue
  85.               {
  86.                   int            signature;
  87.                   struct t_queue *next;
  88.  
  89.                   TCB            *task_h;     /* Task queue */
  90.                   TCB            *task_t;
  91.  
  92.                   int            q_size;      /* Message queue */
  93.                   int            numele;
  94.                   void           **headp;
  95.                   void           **tailp;
  96.                   void           *queue[1];
  97.               }
  98.               T_QUEUE;
  99.  
  100.  
  101.        
  102. ________________________________________________________________
  103.  
  104. _______________________________________________________________
  105.                                      Fig.  3: 
  106.  
  107.  
  108.                     T_QUEUE                        T_QUEUE
  109.                     +----------+                   +----------+ 
  110.         T_queues--->|  next----|------------------>| next (0) |
  111.                     |          |                   |          |
  112.             +-------|--t_head  |           +-------|--tailp   |
  113.             |       |  t_tail--|--+        |  +----|--headp   |
  114.             |       +----------+  |        |  |    +----------+
  115.             |                     |        |  +--->|    
  116. *----|-->"message 1"
  117.             |                     |        |       +----------+
  118.             |   TCB               |        |       |    
  119. *----|-->"message 2"
  120.             |   +--------+        |        |       +----------+
  121.             +-->|  next  |        |        +------>|    
  122. *----|-->"message 3"
  123.                 |    |   |        |                +----------+
  124.                 +----|---+        |                |space for |
  125.                      |            |                |  other   |
  126.                      |            |                | messages |
  127.                 TCB  V            |                +----------+
  128.                 +--------+        |
  129.                 |  next  |<-------+  
  130.                 |   (0)  |
  131.                 +--------+
  132.  
  133. A list of two queues, the first of which has two tasks waiting at
  134. it and the second of which has three messages enqueued and no
  135. tasks waiting. Only relevant fields are shown.
  136.  
  137. ________________________________________________________________
  138.  
  139. _______________________________________________________________
  140.                                    Example  3: 
  141.  
  142.                 void    *pq_look( queue )
  143.                 PQ      *queue;
  144.                 {
  145.                     return queue->nitems ?  queue->heap : NULL ;
  146.                 }
  147.  
  148.                 /*--------------------------------------------*/
  149.  
  150.                 int  pq_replace( p, target, item )
  151.                 PQ   *p;
  152.                 void *item, *target;
  153.                 {
  154.                     int slots_in_use;
  155.  
  156.                     if( slots_in_use = p->nitems )
  157.                     {
  158.                         memcpy( target,  p->heap, p->itemsize );
  159.                         memcpy( p->heap, item,    p->itemsize );
  160.                         reheap_down( p, p->heap );
  161.                     }
  162.  
  163.                     return slots_in_use ;
  164.                 }
  165.  
  166.        
  167. ________________________________________________________________
  168.